package model;

import java.util.Date;
import java.util.Enumeration;
import java.util.Vector;

import dao.CustomerDAO;
import dao.ReservationDAO;

public class ListReservation {
	private Vector reservations;
	private ReservationDAO reservationDAO;

	public ListReservation() {
		reservations=new Vector();
	
	}
	public void connect()
	{
		reservationDAO = new ReservationDAO();
	}

	public Vector getReservations() {
		return reservations;
	}

	public void setReservations(Vector reservations) {
		this.reservations = reservations;
	}

	// make reservaton
	public boolean addreservation(int reservation_id, int customer_id,
			int room_id, Date expected_arrive_date,
			Date expected_departure_date, int status, String note,
			int employee_reservation) {

		boolean re = false;

		Reservation reser = new Reservation(reservation_id, customer_id,
				room_id, expected_arrive_date, expected_departure_date, status,
				note, employee_reservation);
		reservations.addElement(reser);
		return re;
	}

	public boolean addreservation(Reservation reser) {
		boolean re = false;
		reservations.addElement(reser);
		reservationDAO.insert_reservation(reser);
		return re;
	}

	public boolean addreservationTest(Reservation reser) {
		boolean re = false;
		reservations.addElement(reser);

		return re;
	}

	// cancle reservation
	public boolean delete_reservation(int reservation_id) {
		boolean re = false;
		Enumeration emp = reservations.elements();
		while (emp.hasMoreElements()) {
			Reservation each = (Reservation) emp.nextElement();
			if (reservation_id == each.getCustomer_id()) {
				reservations.removeElement(each);
				re = true;
				break;
			}
		}
		return re;

	}

	// find search
	public Reservation search_reservation(int reservation_id) {
		boolean re = false;

		Enumeration emp = reservations.elements();
		while (emp.hasMoreElements()) {
			Reservation each = (Reservation) emp.nextElement();
			if (reservation_id == each.getReservation_id()) {
				return each;

			}
		}
		return new Reservation();

	}

	// update reservation
	public boolean updatereservation(int reservation_id) {
		boolean re = false;
		Reservation each = null;
		int index = 0;
		Enumeration r = reservations.elements();
		while (r.hasMoreElements()) {
			each = (Reservation) r.nextElement();
			if ((reservation_id == each.getRoom_id())) {
				index = reservations.indexOf(each);
				break;
			}
		}
		if (each != null) {
			reservations.set(index, each);
			re = true;
		}

		return re;
	}

	public boolean updatereservation(Reservation res) {
		boolean re = false;
		Reservation each = null;
		int index = 0;
		Enumeration r = reservations.elements();
		while (r.hasMoreElements()) {
			each = (Reservation) r.nextElement();
			if ((res.getReservation_id() == each.getRoom_id())) {
				index = reservations.indexOf(each);
				break;
			}
		}
		if (each != null) {
			reservations.set(index, each);
			re = true;
		}

		return re;
	}
	
	public void show() {
		System.out.println("List:");
		Enumeration r = reservations.elements();
		while (r.hasMoreElements()) {
			Reservation each = (Reservation) r.nextElement();
			System.out.println(each.toString());
		}
	}
}
